package org.xczy.boot.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {

  public static final  String EXCHANGE_NAME = "ExchangesYX"; // 交换机名称
  public static final  String QUEUE_NAME = "queuesYX"; // 队列名称

  @Bean("exchange") // 配置交换机
  public Exchange exchange(){
    return ExchangeBuilder
        .topicExchange(EXCHANGE_NAME) // 构建交换机
        .durable(true)                // 设置持久化，重启mq后依然存在
        .build();
  }

  @Bean("queue") // 配置队列
  public Queue queue(){
    return QueueBuilder
        .durable(QUEUE_NAME) // 构建队列
        .build();
  }

  @Bean // 配置队列和交换机的绑定关系
  public Binding bindQueueExchange(@Qualifier("queue") Queue queue, @Qualifier("exchange") Exchange exchange){
    return BindingBuilder.bind(queue).to(exchange).with("boot.#").noargs();
  }

}
